﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Csla;

namespace Asah.SiteWorx.ProductCatalog
{
    [Serializable()]
    public class CatalogInfo : Csla.ReadOnlyBase<CatalogInfo>
    {
        private int _id;
        private string _name;
        private string _description;
        private string _coverProductImagePath;
        private Membership.User _createdBy;
        private SmartDate _createdDate;
        private Membership.User _lastUpdatedBy;
        private SmartDate _lastUpdatedDate;

        public int ID
        {
            get
            {
                return _id;
            }
            internal set
            {
                _id = value;
            }
        }

        public string Name
        {
            get
            {
                return _name;
            }
            internal set
            {
                _name = value;
            }
        }

        public string Description
        {
            get
            {
                return _description;
            }
            internal set
            {
                _description = value;
            }
        }

        public string CoverProductImagePath
        {
            get
            {
                return _coverProductImagePath;
            }
            internal set
            {
                _coverProductImagePath = value;
            }
        }

        public Membership.User CreatedBy
        {
            get
            {
               return _createdBy;
            }
            internal set
            {
                _createdBy = value;
            }
        }

        public string CreatedDate
        {
            get
            {
                return _createdDate.ToString("g");
            }
            internal set
            {
                _createdDate.Text = value;
            }
        }

        public Membership.User LastUpdatedBy
        {
            get
            {
                return _lastUpdatedBy;
            }
            internal set
            {
                _lastUpdatedBy = value;
            }
        }

        public string LastUpdatedDate
        {
            get
            {
                return _lastUpdatedDate.ToString("g");
            }
            internal set
            {
                _lastUpdatedDate.Text = value;
            }
        }

        public override string ToString()
        {
            return _name;
        }

        protected override object GetIdValue()
        {
            return _id;
        }

        internal CatalogInfo()
        {
            // require use of factory methods
        }

        internal CatalogInfo(int id, string name, string description, string coverProductImagePath,
                             Guid createdBy, SmartDate createdDate, Guid lastUpdatedBy, SmartDate lastUpdatedDate)
        {
            _id = id;
            _name = name;
            _description = description;
            _coverProductImagePath = coverProductImagePath;
            _createdBy = Membership.User.GetUser(createdBy);
            _createdDate = createdDate;
            _lastUpdatedBy = Membership.User.GetUser(lastUpdatedBy);
            _lastUpdatedDate = lastUpdatedDate;
        }
    }
}
